/*
 * 文  件   名： HomeFoodAndDrinkActivity.java
 * 版          权： Copyright GoPawPaw All Rights Reserved.
 * 描          述：[该类的简要描述]
 * 创  建   人： LiJinHua
 * 创建时间： 2012-5-27
 * 
 * 修   改  人：
 * 修改时间：
 * 修改内容：[修改内容]
 */
package com.longevityassistant.activity.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ViewFlipper;

import com.longevityassistant.activity.BaseTabParentActivity;
import com.longevityassistant.activity.R;

/**
 * @author LiJinHua
 * @date 2012-5-27
 * @version [Android 1.0.0, 2012-5-27]
 * @description
 */
public class HomeFoodAndDrinkActivity extends BaseTabParentActivity {

	/**
	 * 在启动本页面时，可指定进入页面显示的是那个标签，此key用于intent传入的参数，values值在ViewTabType中指定
	 */
	public static final String KEY_WHICH_TAB = "which_tab";
	
	/**
	 * tab类型
	 * 
	 * @author EX-LIJINHUA001
	 * @version [Android PABank C01, 2012-2-27]
	 */
	public static class ViewTabType {
		/**
		 * 默认为提前还款
		 */
		private static final int DEFUALT = R.id.tab_left;
		/**
		 * 提前还款
		 */
		public static final int LOAN_MANAGE_PRE_PAYMENT = R.id.tab_left;
		/**
		 * 还款方式
		 */
		public static final int LOAN_MANAGE_TYPE = R.id.tab_right;

	}

	/**
	 * TAB标签
	 */
	private RadioButton rb1, rb2;

	/**
	 * 背景图片
	 */
	private ImageView mImageViewBackground;

	/**
	 * 手势动画View
	 */
	private ViewFlipper mViewFlipperBody;

	/**
	 * 3个tab控件的父View
	 */
	private RadioGroup mRadioGroupTab;

	/**
	 * 是否初始化
	 */
	private boolean isFirstInitTab = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.investment_main_tab2);
		setTopTitle(R.string.food_and_drink_title);
		initView();

	}

	/**
	 * 初始化View
	 */
	private void initView() {
		rb1 = (RadioButton) findViewById(R.id.tab_left);
		rb2 = (RadioButton) findViewById(R.id.tab_right);

		mRadioGroupTab = (RadioGroup) findViewById(R.id.tab_radio);
		mImageViewBackground = (ImageView) findViewById(R.id.tab_image_bg);
		mViewFlipperBody = (ViewFlipper) findViewById(R.id.bodyView);
		mRadioGroupTab.setOnCheckedChangeListener(this);
		rb1.setText(R.string.food_and_drink_tab_now);
		rb2.setText(R.string.food_and_drink_tab_his);
		
		getImageButton2().setVisibility(View.GONE);
		initTab();
	}

	/**
	 * 初始化tab控件
	 */
	private void initTab() {
		Class<?> intentClass[] = new Class[] {
				FoodAndDrinkNowActivity.class,
				FoodAndDrinkHisActivity.class};
		for (int i = 0; i < intentClass.length; i++) {
			String id = "activity" + i;
			Intent intent = new Intent(HomeFoodAndDrinkActivity.this, intentClass[i]);
			View view = getLocalActivityManager().startActivity(id, intent)
					.getDecorView();
			mViewFlipperBody.addView(view);
		}
		if (isFirstInitTab) {
			int whichTab = getIntent().getIntExtra(KEY_WHICH_TAB,
					ViewTabType.DEFUALT);
			checkTab(mRadioGroupTab, mImageViewBackground, whichTab);
			// ((BaseTabActivity)getLocalActivityManager().getActivity("activity0")).onIntoScreen(0);
			isFirstInitTab = false;
		}
	}

	/**
	 * 监听tab 选中事件
	 * @param group 按钮组
	 * @param checkId 点击的是那个标签
	 * @see android.widget.RadioGroup.OnCheckedChangeListener#onCheckedChanged(android.widget.RadioGroup, int)
	 */
	public void onCheckedChanged(RadioGroup group, int checkId) {
		// TODO Auto-generated method stub

		switch (checkId) {
		case R.id.tab_left:
			showView(0, this, mViewFlipperBody, 0);
			break;
		case R.id.tab_right:
			showView(1, this, mViewFlipperBody, 0);
			break;
		default:
			break;
		}
		
		
		if (isFirstInitTab) {
			
			return;
		}
		
		super.startAnimation(group, mImageViewBackground, checkId);
	}

}

